<template>
  <div>

    <!-- 条件搜托条 -->
    <div class="topSearch" style=" margin:0 0 10px">
      <!-- <div class="leftBox">
        <div class="searchbox">
        <em>财务人员姓名：</em>
        <el-input v-model="searchBox.name" size="small" style="width:250px" placeholder="财务人员姓名"></el-input>
        </div>
        <div class="searchbox">
        <el-button type="primary" @click="getList" size="mini">搜索</el-button>
        </div>
      </div> -->
      <div class="rightBox">
         <el-button type="primary" size="mini" @click="addNew">新增学年</el-button>
      </div>
      <div class="clear"></div>
    </div>

    <div class="contentBox">
      <el-table :data="tabelData" border stripe style="width: 100%" height="90%">
        <el-table-column prop="timeName" label="学年名称"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button  @click="edit(scope.row)" type="primary" size="mini">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <el-dialog :title="layerTitle" :visible.sync="dialogVisible" width="30%">
      <div class="layerMaxHeight layerBox">
        <el-input v-model="saveBox.input" placeholder="请输入内容"  maxlength="30" show-word-limit></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false; input=''">取 消</el-button>
        <el-button type="primary" @click="saveYearName">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
export default {
  name:'SchoolYeatSet',
  data() {
    return {
      tabelData:[],
      layerTitle:'',
      dialogVisible:false,
      saveBox:{
        yid:'',
        input:'',
      }
    }
  },
  mounted() {
    this.getYearList();
  },
  methods: {
    // 获取学年列表
    getYearList(){
      this.$api.systemSetup.GetYearsList().then(res=>{
        console.log("获取时间列表",res)
        this.tabelData = res.data.result.list;
      })
    },
    // 新增学年
    addNew(){
      this.layerTitle = "新增学年";
      this.dialogVisible = true;
    },
    // 修改学年
    edit(obg){
      this.layerTitle = "修改学年";
      this.saveBox.yid = obg.id;
      this.saveBox.input = obg.timeName;
      this.dialogVisible = true;
    },
    // 保存年份名称
    saveYearName(){
      this.$api.systemSetup.SaveYearName(this.saveBox.yid,this.saveBox.input).then(res=>{
        if(res.data.result){
          this.$message.success("保存年份名称成功!")
          this.getYearList();
          this.dialogVisible =  false;
        }
      })
    }
  },
}
</script>

<style>

</style>
